package com.demo.convert.word2html.office2007.support;

import lombok.extern.slf4j.Slf4j;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;

import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * @author fenggang.li
 * @create 2019-09-11 13:52
 */
@Slf4j
public class CTRPrProxy extends CTRPrProxyAdapter {

    /**
     * 字体名集合
     */
    private static final Set<String> FONT_NAME_SET = initFontNameSet();

    public CTRPrProxy(CTRPr target) {
        super(target);
    }

    public static Set<String> initFontNameSet() {
        Set<String> fontNameSet = new HashSet<>();
        fontNameSet.add("DengXian Light");
        fontNameSet.add("SimSun");
        return Collections.unmodifiableSet(fontNameSet);
    }

    @Override
    public CTFonts getRFonts() {
        CTFonts rFonts = super.getRFonts();
        if (Objects.isNull(rFonts)) {
            log.debug("font is null");
        } else if (FONT_NAME_SET.contains(rFonts.getAscii())) {
            log.debug("Keep {} as is.", rFonts.getAscii());
        } else {
            log.debug("Filter font \"{}\" with ascii name \"{}\"", rFonts.getClass().getName(), rFonts.getAscii());
            rFonts = new RFontProxy(rFonts, "SimSun");
        }
        return rFonts;
    }

}
